﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Xml.Utility;

namespace Portal.Cms.Model
{
    public class DataCollectionCls
    {
        public string DataCollectionId;
        public string GroupDataId;
        public string FolderName;
        public string Description;
        public string ParentDataCollectionId;
        public int SortIndex;
    }

    public class DataCollectionParser
    {
        public static DataCollectionCls CreateInstance()
        {
            //tao 1 class trang....
            DataCollectionCls oDataCollectionCls = new DataCollectionCls();
            return oDataCollectionCls;
        }

        public static DataCollectionCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            DataCollectionCls oDataCollectionCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oDataCollectionCls;
        }


        public static DataCollectionCls ParseFromDataRow(DataRow dr)
        {
            DataCollectionCls oDataCollectionCls = new DataCollectionCls();
            oDataCollectionCls.DataCollectionId = XmlUtility.GetString(dr, "DataCollectionId", true);
            oDataCollectionCls.GroupDataId = XmlUtility.GetString(dr, "GroupDataId", true);
            oDataCollectionCls.FolderName = XmlUtility.GetString(dr, "FolderName", true);
            oDataCollectionCls.Description = XmlUtility.GetString(dr, "Description", true);
            oDataCollectionCls.Description = XmlUtility.GetString(dr, "Description", true);
            oDataCollectionCls.ParentDataCollectionId = XmlUtility.GetString(dr, "ParentDataCollectionId", true);
            oDataCollectionCls.SortIndex = XmlUtility.GetInt(dr, "SortIndex", true);

            return oDataCollectionCls;
        }

        public static DataCollectionCls[] ParseFromDataTable(DataTable dtTable)
        {
            DataCollectionCls[] DataCollections = new DataCollectionCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                DataCollections[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return DataCollections;
        }

        public static DataCollectionCls[] ParseMultiRecordFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            if (ds.Tables.Count == 0)
            {
                return new DataCollectionCls[0];
            }
            DataCollectionCls[] DataCollections = new DataCollectionCls[ds.Tables[0].Rows.Count];
            for (int iIndex = 0; iIndex < ds.Tables[0].Rows.Count; iIndex++)
            {
                DataCollections[iIndex] = ParseFromDataRow(ds.Tables[0].Rows[iIndex]);
            }
            return DataCollections;
        }
    }
}

